package cn.dmrliu.edu.publish.controller;

import cn.dmrliu.edu.publish.bean.InteractionReview;
import cn.dmrliu.edu.publish.service.InteractionReviewService;
import cn.dmrliu.edu.publish.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/edu/realtime/course")
public class CourseController {
    @Autowired
    private InteractionReviewService interactionReviewService;

    @RequestMapping("/review")
    public String getReview(@RequestParam(value = "date", defaultValue = "1") Integer date) {
        if (date == 1) {
            date = DateUtil.now();
        }
        List<InteractionReview> list = interactionReviewService.getReview(date);


        return "{\n" +
                "  \"status\": 0,\n" +
                "  \"msg\": \"\",\n" +
                "  \"data\": {\n" +
                "    \"total\": 2,\n" +
                "    \"columns\": [\n" +
                "      {\n" +
                "        \"name\": \"课程\",\n" +
                "        \"id\": \"courseName\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"用户平均评分\",\n" +
                "        \"id\": \"avgScore\",\n" +
                "        \"accuracy\": 2\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"评价用户数\",\n" +
                "        \"id\": \"userCt\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"好评率\",\n" +
                "        \"id\": \"fiveRate\",\n" +
                "        \"accuracy\": 2\n" +
                "      }\n" +
                "    ],\n" +
                "    \"rows\": [" + StringUtils.join(list, ",") + "]\n" +
                "  }\n" +
                "}";
    }
}
